home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
image.ed
/
bigpixel.c
next >
Wrap
C/C++ Source or Header
|
1985-10-26
|
6KB
|
193 lines
/************* bigpixel2.c ***************/
#include "intuall.h"
#include "imageedit.h"
extern struct RastPort *rp;
extern struct Screen *screen;
extern struct Window *w;
extern struct frame f[];
extern SHORT framewidth, frameheight, editright, editbottom;
extern SHORT bobdepth;
SHORT zeros[41]=0;
/* is a variable within a specified range? */
/* ******************************************************************** */
/* draw a 3-by-3 version of a pixel within a 4-by-4 area... the mouse
reporting will give us positions within the rectangle... have to adjust
to an even boundary to assure the correct position is written
(divide by 4 and multiply by 4 to zero out last 2 bits) */
/* ******************************************************************** */
bigpixel(x,y)
SHORT x,y;
{
SHORT i,j;
x = ((x >> 2)<<2); y=((y >> 2)<<2);
for(i=0; i<3; i++)
for(j=0; j<3; j++)
WritePixel(rp,x+i,y+j);
return(0);
}
/* create a bitmap into which the aligned object can be copied, and a
* larger bitmap into which the expansion can occur in the background
*/
struct BitMap bigbitmap;
struct BitMap smallbitmap;
struct RastPort bigrastport;
struct RastPort smallrastport;
struct RastPort undorastport;
struct BitMap undobitmap;
workbitmaps()
{
SHORT i;
InitRastPort(&bigrastport);
InitRastPort(&smallrastport);
InitRastPort(&undorastport);
bigrastport.BitMap = &bigbitmap;
smallrastport.BitMap = &smallbitmap;
undorastport.BitMap = &undobitmap;
InitBitMap(&bigbitmap,bobdepth,344,224);
InitBitMap(&smallbitmap,bobdepth,FRAMEWIDTH+24,FRAMEHEIGHT);
InitBitMap(&undobitmap,bobdepth,FRAMEWIDTH+24,FRAMEHEIGHT);
for(i=0; i<bobdepth; i++)
bigbitmap.Planes[i]=(PLANEPTR)AllocRaster( 344, 224);
for(i=0; i<bobdepth; i++)
smallbitmap.Planes[i]=(PLANEPTR)AllocRaster(FRAMEWIDTH+24,
FRAMEHEIGHT);
for(i=0; i<bobdepth; i++)
undobitmap.Planes[i]=(PLANEPTR)AllocRaster(FRAMEWIDTH+24,
FRAMEHEIGHT);
for(i=0; i<bobdepth; i++)
if(smallbitmap.Planes[i] == 0 || bigbitmap.Planes[i] == 0 ||
undobitmap.Planes[i] == 0)
{
CloseWindow(w);
CloseScreen(screen);
exit(999); /* out of memory */
}
return(0);
}
FreeMyMemory()
{
SHORT i;
for(i=0; i<bobdepth; i++)
FreeRaster(bigbitmap.Planes[i],344, 224);
for(i=0; i<bobdepth; i++)
FreeRaster(smallbitmap.Planes[i],FRAMEWIDTH+24, FRAMEHEIGHT);
for(i=0; i<bobdepth; i++)
FreeRaster(undobitmap.Planes[i],FRAMEWIDTH+24, FRAMEHEIGHT);
return(0);
}
/*
* copy memory expanding each bit to four bits.
* The count refers to the number of byte in the source.
*
* Special purpose routine, takes one line of source, expands into
* one line of destination bitmap for each call.
*/
/* ******************************************************************** */
/* construct a table of values which translate a 1-bit wide item into
a four-bit wide item. There are 16 entries in the table translating
4-bit values into 16 equivalent word values */
USHORT exptable[] = { 0x0000, 0x000e, 0x00e0, 0x00ee,
0x0e00, 0x0e0e, 0x0ee0, 0x0eee,
0xe000, 0xe00e, 0xe0e0, 0xe0ee,
0xee00, 0xee0e, 0xeee0, 0xeeee };
expand(d, s, count)
PLANEPTR d,s;
register count;
{
register USHORT *dest; /* destination array */
register UBYTE *src; /* source array */
register UBYTE a;
/* expand 4 bits to 16 bits, twice */
dest = (USHORT *)(( d >> 1 ) << 1);
src = (UBYTE *)s;
while (count)
{
a = *src;
*dest++ = exptable [ a >> 4 ];
*dest++ = exptable [ a & 0xf ];
src++;
count--;
}
}
/* After copying the non-aligned info from the real raster into a byte-
* aligned rastport, expand this new stuff into a word-aligned rastport
* offscreen. Then blit it from the expanded area onto the screen.
*/
doexpand(n)
SHORT n;
{
SHORT i,j;
PLANEPTR p, q; /* both pointer variables */
ClipBlit(rp, /* source rastport */
f[n].xmin, /* source location x and y */
f[n].ymin,
&smallrastport, /* small rastport destination rastport */
0, /* destination x and y */
0,
framewidth, /* bit-size of rectangle */
frameheight,
0xc0); /* c0 means bit-for bit in all planes */
for(i=0; i<bobdepth; i++)
{
p = smallbitmap.Planes[i];
q = bigbitmap.Planes[i];
for(j=0; j<frameheight; j++)
{
expand(q,p,10);
q += bigbitmap.BytesPerRow;
expand(q,p,10);
q += bigbitmap.BytesPerRow;
expand(q,p,10);
q += bigbitmap.BytesPerRow;
expand(q,zeros,10);
q += bigbitmap.BytesPerRow;
p += smallbitmap.BytesPerRow;
}
}
ClipBlit(&bigrastport,
0,
0,
rp,
EDITLEFT,
EDITTOP,
editright-EDITLEFT,
editbottom-EDITTOP,
0xc0);
return(0);
}